{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# pandas案例导入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_changes = np.random.normal(0, 1, (10, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.0898243 ,  0.60345257,  0.31913613, -0.49325401,  0.49131242],\n",
       "       [-0.86697938, -0.80076994, -0.15674492,  0.35278585, -1.48140365],\n",
       "       [-1.59717191, -1.61579297, -1.57000085,  0.39853211,  0.7655731 ],\n",
       "       [-1.12588418,  0.16160773, -0.56114914, -1.9534698 , -1.08915491],\n",
       "       [-0.51609472,  0.192761  , -0.65065503, -1.15697595, -2.31499457],\n",
       "       [-1.04385883, -1.28967309,  0.30537855,  1.7146177 , -0.76918391],\n",
       "       [ 0.70437709,  1.19455524, -0.40024919, -2.15978911, -0.83744933],\n",
       "       [-0.65843121,  2.12114907,  0.14506256,  1.38846215,  0.49110284],\n",
       "       [ 1.29342334,  0.59772695,  0.58492959,  0.44113981, -0.38463861],\n",
       "       [-0.26661357,  1.01591508, -0.75953891, -0.51662656,  0.57370983]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_changes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_rise = pd.DataFrame(stock_changes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.089824</td>\n",
       "      <td>0.603453</td>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.491312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>-1.481404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>0.765573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.125884</td>\n",
       "      <td>0.161608</td>\n",
       "      <td>-0.561149</td>\n",
       "      <td>-1.953470</td>\n",
       "      <td>-1.089155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.516095</td>\n",
       "      <td>0.192761</td>\n",
       "      <td>-0.650655</td>\n",
       "      <td>-1.156976</td>\n",
       "      <td>-2.314995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-1.043859</td>\n",
       "      <td>-1.289673</td>\n",
       "      <td>0.305379</td>\n",
       "      <td>1.714618</td>\n",
       "      <td>-0.769184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.704377</td>\n",
       "      <td>1.194555</td>\n",
       "      <td>-0.400249</td>\n",
       "      <td>-2.159789</td>\n",
       "      <td>-0.837449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.658431</td>\n",
       "      <td>2.121149</td>\n",
       "      <td>0.145063</td>\n",
       "      <td>1.388462</td>\n",
       "      <td>0.491103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1.293423</td>\n",
       "      <td>0.597727</td>\n",
       "      <td>0.584930</td>\n",
       "      <td>0.441140</td>\n",
       "      <td>-0.384639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.266614</td>\n",
       "      <td>1.015915</td>\n",
       "      <td>-0.759539</td>\n",
       "      <td>-0.516627</td>\n",
       "      <td>0.573710</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4\n",
       "0  0.089824  0.603453  0.319136 -0.493254  0.491312\n",
       "1 -0.866979 -0.800770 -0.156745  0.352786 -1.481404\n",
       "2 -1.597172 -1.615793 -1.570001  0.398532  0.765573\n",
       "3 -1.125884  0.161608 -0.561149 -1.953470 -1.089155\n",
       "4 -0.516095  0.192761 -0.650655 -1.156976 -2.314995\n",
       "5 -1.043859 -1.289673  0.305379  1.714618 -0.769184\n",
       "6  0.704377  1.194555 -0.400249 -2.159789 -0.837449\n",
       "7 -0.658431  2.121149  0.145063  1.388462  0.491103\n",
       "8  1.293423  0.597727  0.584930  0.441140 -0.384639\n",
       "9 -0.266614  1.015915 -0.759539 -0.516627  0.573710"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_rise"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10, 5)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_rise.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_rise.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_code = [\"股票{}\".format(i+1) for i in range(stock_rise.shape[0])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['股票1', '股票2', '股票3', '股票4', '股票5', '股票6', '股票7', '股票8', '股票9', '股票10']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>股票1</th>\n",
       "      <td>0.089824</td>\n",
       "      <td>0.603453</td>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.491312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票2</th>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>-1.481404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票3</th>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>0.765573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票4</th>\n",
       "      <td>-1.125884</td>\n",
       "      <td>0.161608</td>\n",
       "      <td>-0.561149</td>\n",
       "      <td>-1.953470</td>\n",
       "      <td>-1.089155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票5</th>\n",
       "      <td>-0.516095</td>\n",
       "      <td>0.192761</td>\n",
       "      <td>-0.650655</td>\n",
       "      <td>-1.156976</td>\n",
       "      <td>-2.314995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票6</th>\n",
       "      <td>-1.043859</td>\n",
       "      <td>-1.289673</td>\n",
       "      <td>0.305379</td>\n",
       "      <td>1.714618</td>\n",
       "      <td>-0.769184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票7</th>\n",
       "      <td>0.704377</td>\n",
       "      <td>1.194555</td>\n",
       "      <td>-0.400249</td>\n",
       "      <td>-2.159789</td>\n",
       "      <td>-0.837449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票8</th>\n",
       "      <td>-0.658431</td>\n",
       "      <td>2.121149</td>\n",
       "      <td>0.145063</td>\n",
       "      <td>1.388462</td>\n",
       "      <td>0.491103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票9</th>\n",
       "      <td>1.293423</td>\n",
       "      <td>0.597727</td>\n",
       "      <td>0.584930</td>\n",
       "      <td>0.441140</td>\n",
       "      <td>-0.384639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票10</th>\n",
       "      <td>-0.266614</td>\n",
       "      <td>1.015915</td>\n",
       "      <td>-0.759539</td>\n",
       "      <td>-0.516627</td>\n",
       "      <td>0.573710</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             0         1         2         3         4\n",
       "股票1   0.089824  0.603453  0.319136 -0.493254  0.491312\n",
       "股票2  -0.866979 -0.800770 -0.156745  0.352786 -1.481404\n",
       "股票3  -1.597172 -1.615793 -1.570001  0.398532  0.765573\n",
       "股票4  -1.125884  0.161608 -0.561149 -1.953470 -1.089155\n",
       "股票5  -0.516095  0.192761 -0.650655 -1.156976 -2.314995\n",
       "股票6  -1.043859 -1.289673  0.305379  1.714618 -0.769184\n",
       "股票7   0.704377  1.194555 -0.400249 -2.159789 -0.837449\n",
       "股票8  -0.658431  2.121149  0.145063  1.388462  0.491103\n",
       "股票9   1.293423  0.597727  0.584930  0.441140 -0.384639\n",
       "股票10 -0.266614  1.015915 -0.759539 -0.516627  0.573710"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(stock_changes, index=stock_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "date = pd.date_range(start=\"20190403\", periods=stock_rise.shape[1], freq=\"B\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2019-04-03', '2019-04-04', '2019-04-05', '2019-04-08',\n",
       "               '2019-04-09'],\n",
       "              dtype='datetime64[ns]', freq='B')"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_c = pd.DataFrame(stock_changes, index=stock_code, columns=date)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-04-03 00:00:00</th>\n",
       "      <th>2019-04-04 00:00:00</th>\n",
       "      <th>2019-04-05 00:00:00</th>\n",
       "      <th>2019-04-08 00:00:00</th>\n",
       "      <th>2019-04-09 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>股票1</th>\n",
       "      <td>0.089824</td>\n",
       "      <td>0.603453</td>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.491312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票2</th>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>-1.481404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票3</th>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>0.765573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票4</th>\n",
       "      <td>-1.125884</td>\n",
       "      <td>0.161608</td>\n",
       "      <td>-0.561149</td>\n",
       "      <td>-1.953470</td>\n",
       "      <td>-1.089155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票5</th>\n",
       "      <td>-0.516095</td>\n",
       "      <td>0.192761</td>\n",
       "      <td>-0.650655</td>\n",
       "      <td>-1.156976</td>\n",
       "      <td>-2.314995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票6</th>\n",
       "      <td>-1.043859</td>\n",
       "      <td>-1.289673</td>\n",
       "      <td>0.305379</td>\n",
       "      <td>1.714618</td>\n",
       "      <td>-0.769184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票7</th>\n",
       "      <td>0.704377</td>\n",
       "      <td>1.194555</td>\n",
       "      <td>-0.400249</td>\n",
       "      <td>-2.159789</td>\n",
       "      <td>-0.837449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票8</th>\n",
       "      <td>-0.658431</td>\n",
       "      <td>2.121149</td>\n",
       "      <td>0.145063</td>\n",
       "      <td>1.388462</td>\n",
       "      <td>0.491103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票9</th>\n",
       "      <td>1.293423</td>\n",
       "      <td>0.597727</td>\n",
       "      <td>0.584930</td>\n",
       "      <td>0.441140</td>\n",
       "      <td>-0.384639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票10</th>\n",
       "      <td>-0.266614</td>\n",
       "      <td>1.015915</td>\n",
       "      <td>-0.759539</td>\n",
       "      <td>-0.516627</td>\n",
       "      <td>0.573710</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      2019-04-03  2019-04-04  2019-04-05  2019-04-08  2019-04-09\n",
       "股票1     0.089824    0.603453    0.319136   -0.493254    0.491312\n",
       "股票2    -0.866979   -0.800770   -0.156745    0.352786   -1.481404\n",
       "股票3    -1.597172   -1.615793   -1.570001    0.398532    0.765573\n",
       "股票4    -1.125884    0.161608   -0.561149   -1.953470   -1.089155\n",
       "股票5    -0.516095    0.192761   -0.650655   -1.156976   -2.314995\n",
       "股票6    -1.043859   -1.289673    0.305379    1.714618   -0.769184\n",
       "股票7     0.704377    1.194555   -0.400249   -2.159789   -0.837449\n",
       "股票8    -0.658431    2.121149    0.145063    1.388462    0.491103\n",
       "股票9     1.293423    0.597727    0.584930    0.441140   -0.384639\n",
       "股票10   -0.266614    1.015915   -0.759539   -0.516627    0.573710"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10, 5)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['股票1', '股票2', '股票3', '股票4', '股票5', '股票6', '股票7', '股票8', '股票9', '股票10'], dtype='object')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2019-04-03', '2019-04-04', '2019-04-05', '2019-04-08',\n",
       "               '2019-04-09'],\n",
       "              dtype='datetime64[ns]', freq='B')"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.0898243 ,  0.60345257,  0.31913613, -0.49325401,  0.49131242],\n",
       "       [-0.86697938, -0.80076994, -0.15674492,  0.35278585, -1.48140365],\n",
       "       [-1.59717191, -1.61579297, -1.57000085,  0.39853211,  0.7655731 ],\n",
       "       [-1.12588418,  0.16160773, -0.56114914, -1.9534698 , -1.08915491],\n",
       "       [-0.51609472,  0.192761  , -0.65065503, -1.15697595, -2.31499457],\n",
       "       [-1.04385883, -1.28967309,  0.30537855,  1.7146177 , -0.76918391],\n",
       "       [ 0.70437709,  1.19455524, -0.40024919, -2.15978911, -0.83744933],\n",
       "       [-0.65843121,  2.12114907,  0.14506256,  1.38846215,  0.49110284],\n",
       "       [ 1.29342334,  0.59772695,  0.58492959,  0.44113981, -0.38463861],\n",
       "       [-0.26661357,  1.01591508, -0.75953891, -0.51662656,  0.57370983]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>股票1</th>\n",
       "      <th>股票2</th>\n",
       "      <th>股票3</th>\n",
       "      <th>股票4</th>\n",
       "      <th>股票5</th>\n",
       "      <th>股票6</th>\n",
       "      <th>股票7</th>\n",
       "      <th>股票8</th>\n",
       "      <th>股票9</th>\n",
       "      <th>股票10</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-04-03</th>\n",
       "      <td>0.089824</td>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.125884</td>\n",
       "      <td>-0.516095</td>\n",
       "      <td>-1.043859</td>\n",
       "      <td>0.704377</td>\n",
       "      <td>-0.658431</td>\n",
       "      <td>1.293423</td>\n",
       "      <td>-0.266614</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-04</th>\n",
       "      <td>0.603453</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>0.161608</td>\n",
       "      <td>0.192761</td>\n",
       "      <td>-1.289673</td>\n",
       "      <td>1.194555</td>\n",
       "      <td>2.121149</td>\n",
       "      <td>0.597727</td>\n",
       "      <td>1.015915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-05</th>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>-0.561149</td>\n",
       "      <td>-0.650655</td>\n",
       "      <td>0.305379</td>\n",
       "      <td>-0.400249</td>\n",
       "      <td>0.145063</td>\n",
       "      <td>0.584930</td>\n",
       "      <td>-0.759539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-08</th>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>-1.953470</td>\n",
       "      <td>-1.156976</td>\n",
       "      <td>1.714618</td>\n",
       "      <td>-2.159789</td>\n",
       "      <td>1.388462</td>\n",
       "      <td>0.441140</td>\n",
       "      <td>-0.516627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-09</th>\n",
       "      <td>0.491312</td>\n",
       "      <td>-1.481404</td>\n",
       "      <td>0.765573</td>\n",
       "      <td>-1.089155</td>\n",
       "      <td>-2.314995</td>\n",
       "      <td>-0.769184</td>\n",
       "      <td>-0.837449</td>\n",
       "      <td>0.491103</td>\n",
       "      <td>-0.384639</td>\n",
       "      <td>0.573710</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 股票1       股票2       股票3       股票4       股票5       股票6  \\\n",
       "2019-04-03  0.089824 -0.866979 -1.597172 -1.125884 -0.516095 -1.043859   \n",
       "2019-04-04  0.603453 -0.800770 -1.615793  0.161608  0.192761 -1.289673   \n",
       "2019-04-05  0.319136 -0.156745 -1.570001 -0.561149 -0.650655  0.305379   \n",
       "2019-04-08 -0.493254  0.352786  0.398532 -1.953470 -1.156976  1.714618   \n",
       "2019-04-09  0.491312 -1.481404  0.765573 -1.089155 -2.314995 -0.769184   \n",
       "\n",
       "                 股票7       股票8       股票9      股票10  \n",
       "2019-04-03  0.704377 -0.658431  1.293423 -0.266614  \n",
       "2019-04-04  1.194555  2.121149  0.597727  1.015915  \n",
       "2019-04-05 -0.400249  0.145063  0.584930 -0.759539  \n",
       "2019-04-08 -2.159789  1.388462  0.441140 -0.516627  \n",
       "2019-04-09 -0.837449  0.491103 -0.384639  0.573710  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-04-03 00:00:00</th>\n",
       "      <th>2019-04-04 00:00:00</th>\n",
       "      <th>2019-04-05 00:00:00</th>\n",
       "      <th>2019-04-08 00:00:00</th>\n",
       "      <th>2019-04-09 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>股票1</th>\n",
       "      <td>0.089824</td>\n",
       "      <td>0.603453</td>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.491312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票2</th>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>-1.481404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票3</th>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>0.765573</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     2019-04-03  2019-04-04  2019-04-05  2019-04-08  2019-04-09\n",
       "股票1    0.089824    0.603453    0.319136   -0.493254    0.491312\n",
       "股票2   -0.866979   -0.800770   -0.156745    0.352786   -1.481404\n",
       "股票3   -1.597172   -1.615793   -1.570001    0.398532    0.765573"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-04-03 00:00:00</th>\n",
       "      <th>2019-04-04 00:00:00</th>\n",
       "      <th>2019-04-05 00:00:00</th>\n",
       "      <th>2019-04-08 00:00:00</th>\n",
       "      <th>2019-04-09 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>股票1</th>\n",
       "      <td>0.089824</td>\n",
       "      <td>0.603453</td>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.491312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票2</th>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>-1.481404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票3</th>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>0.765573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票4</th>\n",
       "      <td>-1.125884</td>\n",
       "      <td>0.161608</td>\n",
       "      <td>-0.561149</td>\n",
       "      <td>-1.953470</td>\n",
       "      <td>-1.089155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票5</th>\n",
       "      <td>-0.516095</td>\n",
       "      <td>0.192761</td>\n",
       "      <td>-0.650655</td>\n",
       "      <td>-1.156976</td>\n",
       "      <td>-2.314995</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     2019-04-03  2019-04-04  2019-04-05  2019-04-08  2019-04-09\n",
       "股票1    0.089824    0.603453    0.319136   -0.493254    0.491312\n",
       "股票2   -0.866979   -0.800770   -0.156745    0.352786   -1.481404\n",
       "股票3   -1.597172   -1.615793   -1.570001    0.398532    0.765573\n",
       "股票4   -1.125884    0.161608   -0.561149   -1.953470   -1.089155\n",
       "股票5   -0.516095    0.192761   -0.650655   -1.156976   -2.314995"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-04-03 00:00:00</th>\n",
       "      <th>2019-04-04 00:00:00</th>\n",
       "      <th>2019-04-05 00:00:00</th>\n",
       "      <th>2019-04-08 00:00:00</th>\n",
       "      <th>2019-04-09 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>股票6</th>\n",
       "      <td>-1.043859</td>\n",
       "      <td>-1.289673</td>\n",
       "      <td>0.305379</td>\n",
       "      <td>1.714618</td>\n",
       "      <td>-0.769184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票7</th>\n",
       "      <td>0.704377</td>\n",
       "      <td>1.194555</td>\n",
       "      <td>-0.400249</td>\n",
       "      <td>-2.159789</td>\n",
       "      <td>-0.837449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票8</th>\n",
       "      <td>-0.658431</td>\n",
       "      <td>2.121149</td>\n",
       "      <td>0.145063</td>\n",
       "      <td>1.388462</td>\n",
       "      <td>0.491103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票9</th>\n",
       "      <td>1.293423</td>\n",
       "      <td>0.597727</td>\n",
       "      <td>0.584930</td>\n",
       "      <td>0.441140</td>\n",
       "      <td>-0.384639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票10</th>\n",
       "      <td>-0.266614</td>\n",
       "      <td>1.015915</td>\n",
       "      <td>-0.759539</td>\n",
       "      <td>-0.516627</td>\n",
       "      <td>0.573710</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      2019-04-03  2019-04-04  2019-04-05  2019-04-08  2019-04-09\n",
       "股票6    -1.043859   -1.289673    0.305379    1.714618   -0.769184\n",
       "股票7     0.704377    1.194555   -0.400249   -2.159789   -0.837449\n",
       "股票8    -0.658431    2.121149    0.145063    1.388462    0.491103\n",
       "股票9     1.293423    0.597727    0.584930    0.441140   -0.384639\n",
       "股票10   -0.266614    1.015915   -0.759539   -0.516627    0.573710"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 设置索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_code = [\"股票__{}\".format(i+1) for i in range(stock_rise.shape[0])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_c.index = stock_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-04-03 00:00:00</th>\n",
       "      <th>2019-04-04 00:00:00</th>\n",
       "      <th>2019-04-05 00:00:00</th>\n",
       "      <th>2019-04-08 00:00:00</th>\n",
       "      <th>2019-04-09 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>股票__1</th>\n",
       "      <td>0.089824</td>\n",
       "      <td>0.603453</td>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.491312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__2</th>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>-1.481404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__3</th>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>0.765573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__4</th>\n",
       "      <td>-1.125884</td>\n",
       "      <td>0.161608</td>\n",
       "      <td>-0.561149</td>\n",
       "      <td>-1.953470</td>\n",
       "      <td>-1.089155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__5</th>\n",
       "      <td>-0.516095</td>\n",
       "      <td>0.192761</td>\n",
       "      <td>-0.650655</td>\n",
       "      <td>-1.156976</td>\n",
       "      <td>-2.314995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__6</th>\n",
       "      <td>-1.043859</td>\n",
       "      <td>-1.289673</td>\n",
       "      <td>0.305379</td>\n",
       "      <td>1.714618</td>\n",
       "      <td>-0.769184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__7</th>\n",
       "      <td>0.704377</td>\n",
       "      <td>1.194555</td>\n",
       "      <td>-0.400249</td>\n",
       "      <td>-2.159789</td>\n",
       "      <td>-0.837449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__8</th>\n",
       "      <td>-0.658431</td>\n",
       "      <td>2.121149</td>\n",
       "      <td>0.145063</td>\n",
       "      <td>1.388462</td>\n",
       "      <td>0.491103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__9</th>\n",
       "      <td>1.293423</td>\n",
       "      <td>0.597727</td>\n",
       "      <td>0.584930</td>\n",
       "      <td>0.441140</td>\n",
       "      <td>-0.384639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__10</th>\n",
       "      <td>-0.266614</td>\n",
       "      <td>1.015915</td>\n",
       "      <td>-0.759539</td>\n",
       "      <td>-0.516627</td>\n",
       "      <td>0.573710</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        2019-04-03  2019-04-04  2019-04-05  2019-04-08  2019-04-09\n",
       "股票__1     0.089824    0.603453    0.319136   -0.493254    0.491312\n",
       "股票__2    -0.866979   -0.800770   -0.156745    0.352786   -1.481404\n",
       "股票__3    -1.597172   -1.615793   -1.570001    0.398532    0.765573\n",
       "股票__4    -1.125884    0.161608   -0.561149   -1.953470   -1.089155\n",
       "股票__5    -0.516095    0.192761   -0.650655   -1.156976   -2.314995\n",
       "股票__6    -1.043859   -1.289673    0.305379    1.714618   -0.769184\n",
       "股票__7     0.704377    1.194555   -0.400249   -2.159789   -0.837449\n",
       "股票__8    -0.658431    2.121149    0.145063    1.388462    0.491103\n",
       "股票__9     1.293423    0.597727    0.584930    0.441140   -0.384639\n",
       "股票__10   -0.266614    1.015915   -0.759539   -0.516627    0.573710"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'股票__4'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.index[3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 重设索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>2019-04-03 00:00:00</th>\n",
       "      <th>2019-04-04 00:00:00</th>\n",
       "      <th>2019-04-05 00:00:00</th>\n",
       "      <th>2019-04-08 00:00:00</th>\n",
       "      <th>2019-04-09 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>股票__1</td>\n",
       "      <td>0.089824</td>\n",
       "      <td>0.603453</td>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.491312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>股票__2</td>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>-1.481404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>股票__3</td>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>0.765573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>股票__4</td>\n",
       "      <td>-1.125884</td>\n",
       "      <td>0.161608</td>\n",
       "      <td>-0.561149</td>\n",
       "      <td>-1.953470</td>\n",
       "      <td>-1.089155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>股票__5</td>\n",
       "      <td>-0.516095</td>\n",
       "      <td>0.192761</td>\n",
       "      <td>-0.650655</td>\n",
       "      <td>-1.156976</td>\n",
       "      <td>-2.314995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>股票__6</td>\n",
       "      <td>-1.043859</td>\n",
       "      <td>-1.289673</td>\n",
       "      <td>0.305379</td>\n",
       "      <td>1.714618</td>\n",
       "      <td>-0.769184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>股票__7</td>\n",
       "      <td>0.704377</td>\n",
       "      <td>1.194555</td>\n",
       "      <td>-0.400249</td>\n",
       "      <td>-2.159789</td>\n",
       "      <td>-0.837449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>股票__8</td>\n",
       "      <td>-0.658431</td>\n",
       "      <td>2.121149</td>\n",
       "      <td>0.145063</td>\n",
       "      <td>1.388462</td>\n",
       "      <td>0.491103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>股票__9</td>\n",
       "      <td>1.293423</td>\n",
       "      <td>0.597727</td>\n",
       "      <td>0.584930</td>\n",
       "      <td>0.441140</td>\n",
       "      <td>-0.384639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>股票__10</td>\n",
       "      <td>-0.266614</td>\n",
       "      <td>1.015915</td>\n",
       "      <td>-0.759539</td>\n",
       "      <td>-0.516627</td>\n",
       "      <td>0.573710</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    index  2019-04-03 00:00:00  2019-04-04 00:00:00  2019-04-05 00:00:00  \\\n",
       "0   股票__1             0.089824             0.603453             0.319136   \n",
       "1   股票__2            -0.866979            -0.800770            -0.156745   \n",
       "2   股票__3            -1.597172            -1.615793            -1.570001   \n",
       "3   股票__4            -1.125884             0.161608            -0.561149   \n",
       "4   股票__5            -0.516095             0.192761            -0.650655   \n",
       "5   股票__6            -1.043859            -1.289673             0.305379   \n",
       "6   股票__7             0.704377             1.194555            -0.400249   \n",
       "7   股票__8            -0.658431             2.121149             0.145063   \n",
       "8   股票__9             1.293423             0.597727             0.584930   \n",
       "9  股票__10            -0.266614             1.015915            -0.759539   \n",
       "\n",
       "   2019-04-08 00:00:00  2019-04-09 00:00:00  \n",
       "0            -0.493254             0.491312  \n",
       "1             0.352786            -1.481404  \n",
       "2             0.398532             0.765573  \n",
       "3            -1.953470            -1.089155  \n",
       "4            -1.156976            -2.314995  \n",
       "5             1.714618            -0.769184  \n",
       "6            -2.159789            -0.837449  \n",
       "7             1.388462             0.491103  \n",
       "8             0.441140            -0.384639  \n",
       "9            -0.516627             0.573710  "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c.reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-04-03 00:00:00</th>\n",
       "      <th>2019-04-04 00:00:00</th>\n",
       "      <th>2019-04-05 00:00:00</th>\n",
       "      <th>2019-04-08 00:00:00</th>\n",
       "      <th>2019-04-09 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.089824</td>\n",
       "      <td>0.603453</td>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.491312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>-1.481404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>0.765573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.125884</td>\n",
       "      <td>0.161608</td>\n",
       "      <td>-0.561149</td>\n",
       "      <td>-1.953470</td>\n",
       "      <td>-1.089155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.516095</td>\n",
       "      <td>0.192761</td>\n",
       "      <td>-0.650655</td>\n",
       "      <td>-1.156976</td>\n",
       "      <td>-2.314995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-1.043859</td>\n",
       "      <td>-1.289673</td>\n",
       "      <td>0.305379</td>\n",
       "      <td>1.714618</td>\n",
       "      <td>-0.769184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.704377</td>\n",
       "      <td>1.194555</td>\n",
       "      <td>-0.400249</td>\n",
       "      <td>-2.159789</td>\n",
       "      <td>-0.837449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.658431</td>\n",
       "      <td>2.121149</td>\n",
       "      <td>0.145063</td>\n",
       "      <td>1.388462</td>\n",
       "      <td>0.491103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1.293423</td>\n",
       "      <td>0.597727</td>\n",
       "      <td>0.584930</td>\n",
       "      <td>0.441140</td>\n",
       "      <td>-0.384639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.266614</td>\n",
       "      <td>1.015915</td>\n",
       "      <td>-0.759539</td>\n",
       "      <td>-0.516627</td>\n",
       "      <td>0.573710</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   2019-04-03  2019-04-04  2019-04-05  2019-04-08  2019-04-09\n",
       "0    0.089824    0.603453    0.319136   -0.493254    0.491312\n",
       "1   -0.866979   -0.800770   -0.156745    0.352786   -1.481404\n",
       "2   -1.597172   -1.615793   -1.570001    0.398532    0.765573\n",
       "3   -1.125884    0.161608   -0.561149   -1.953470   -1.089155\n",
       "4   -0.516095    0.192761   -0.650655   -1.156976   -2.314995\n",
       "5   -1.043859   -1.289673    0.305379    1.714618   -0.769184\n",
       "6    0.704377    1.194555   -0.400249   -2.159789   -0.837449\n",
       "7   -0.658431    2.121149    0.145063    1.388462    0.491103\n",
       "8    1.293423    0.597727    0.584930    0.441140   -0.384639\n",
       "9   -0.266614    1.015915   -0.759539   -0.516627    0.573710"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " stock_c.reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 以某列设置新的索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    " df = pd.DataFrame({'month': [1, 4, 7, 10],\n",
    "                    'year': [2012, 2014, 2013, 2014],\n",
    "                    'sale':[55, 40, 84, 31]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>sale</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>55</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4</td>\n",
       "      <td>40</td>\n",
       "      <td>2014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7</td>\n",
       "      <td>84</td>\n",
       "      <td>2013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10</td>\n",
       "      <td>31</td>\n",
       "      <td>2014</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   month  sale  year\n",
       "0      1    55  2012\n",
       "1      4    40  2014\n",
       "2      7    84  2013\n",
       "3     10    31  2014"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>sale</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>year</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2012</th>\n",
       "      <td>1</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014</th>\n",
       "      <td>4</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013</th>\n",
       "      <td>7</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014</th>\n",
       "      <td>10</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      month  sale\n",
       "year             \n",
       "2012      1    55\n",
       "2014      4    40\n",
       "2013      7    84\n",
       "2014     10    31"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.set_index(keys=[\"year\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = df.set_index(keys=[\"year\", \"month\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MultiIndex和panel"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## MultiIndex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>sale</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2012</th>\n",
       "      <th>1</th>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014</th>\n",
       "      <th>4</th>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013</th>\n",
       "      <th>7</th>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014</th>\n",
       "      <th>10</th>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            sale\n",
       "year month      \n",
       "2012 1        55\n",
       "2014 4        40\n",
       "2013 7        84\n",
       "2014 10       31"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex(levels=[[2012, 2013, 2014], [1, 4, 7, 10]],\n",
       "           labels=[[0, 2, 1, 2], [0, 1, 2, 3]],\n",
       "           names=['year', 'month'])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "FrozenList(['year', 'month'])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index.names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "FrozenList([[2012, 2013, 2014], [1, 4, 7, 10]])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index.levels"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## panel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  1],\n",
       "        [ 2,  3],\n",
       "        [ 4,  5]],\n",
       "\n",
       "       [[ 6,  7],\n",
       "        [ 8,  9],\n",
       "        [10, 11]],\n",
       "\n",
       "       [[12, 13],\n",
       "        [14, 15],\n",
       "        [16, 17]],\n",
       "\n",
       "       [[18, 19],\n",
       "        [20, 21],\n",
       "        [22, 23]]])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange(24).reshape(4,3,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = pd.Panel(np.arange(24).reshape(4,3,2),\n",
    "                 items=list('ABCD'),\n",
    "                 major_axis=pd.date_range('20130101', periods=3),\n",
    "                 minor_axis=['first', 'second'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<class 'pandas.core.panel.Panel'>\n",
       "Dimensions: 4 (items) x 3 (major_axis) x 2 (minor_axis)\n",
       "Items axis: A to D\n",
       "Major_axis axis: 2013-01-01 00:00:00 to 2013-01-03 00:00:00\n",
       "Minor_axis axis: first to second"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>12</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>4</td>\n",
       "      <td>10</td>\n",
       "      <td>16</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            A   B   C   D\n",
       "2013-01-01  0   6  12  18\n",
       "2013-01-02  2   8  14  20\n",
       "2013-01-03  4  10  16  22"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p[:,:,\"first\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>first</th>\n",
       "      <th>second</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-01-01</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-02</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-01-03</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            first  second\n",
       "2013-01-01      0       1\n",
       "2013-01-02      2       3\n",
       "2013-01-03      4       5"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p[\"A\", :, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(stock_c[\"2019-04-03\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-04-03 00:00:00</th>\n",
       "      <th>2019-04-04 00:00:00</th>\n",
       "      <th>2019-04-05 00:00:00</th>\n",
       "      <th>2019-04-08 00:00:00</th>\n",
       "      <th>2019-04-09 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>股票__1</th>\n",
       "      <td>0.089824</td>\n",
       "      <td>0.603453</td>\n",
       "      <td>0.319136</td>\n",
       "      <td>-0.493254</td>\n",
       "      <td>0.491312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__2</th>\n",
       "      <td>-0.866979</td>\n",
       "      <td>-0.800770</td>\n",
       "      <td>-0.156745</td>\n",
       "      <td>0.352786</td>\n",
       "      <td>-1.481404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__3</th>\n",
       "      <td>-1.597172</td>\n",
       "      <td>-1.615793</td>\n",
       "      <td>-1.570001</td>\n",
       "      <td>0.398532</td>\n",
       "      <td>0.765573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__4</th>\n",
       "      <td>-1.125884</td>\n",
       "      <td>0.161608</td>\n",
       "      <td>-0.561149</td>\n",
       "      <td>-1.953470</td>\n",
       "      <td>-1.089155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__5</th>\n",
       "      <td>-0.516095</td>\n",
       "      <td>0.192761</td>\n",
       "      <td>-0.650655</td>\n",
       "      <td>-1.156976</td>\n",
       "      <td>-2.314995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__6</th>\n",
       "      <td>-1.043859</td>\n",
       "      <td>-1.289673</td>\n",
       "      <td>0.305379</td>\n",
       "      <td>1.714618</td>\n",
       "      <td>-0.769184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__7</th>\n",
       "      <td>0.704377</td>\n",
       "      <td>1.194555</td>\n",
       "      <td>-0.400249</td>\n",
       "      <td>-2.159789</td>\n",
       "      <td>-0.837449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__8</th>\n",
       "      <td>-0.658431</td>\n",
       "      <td>2.121149</td>\n",
       "      <td>0.145063</td>\n",
       "      <td>1.388462</td>\n",
       "      <td>0.491103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__9</th>\n",
       "      <td>1.293423</td>\n",
       "      <td>0.597727</td>\n",
       "      <td>0.584930</td>\n",
       "      <td>0.441140</td>\n",
       "      <td>-0.384639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>股票__10</th>\n",
       "      <td>-0.266614</td>\n",
       "      <td>1.015915</td>\n",
       "      <td>-0.759539</td>\n",
       "      <td>-0.516627</td>\n",
       "      <td>0.573710</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        2019-04-03  2019-04-04  2019-04-05  2019-04-08  2019-04-09\n",
       "股票__1     0.089824    0.603453    0.319136   -0.493254    0.491312\n",
       "股票__2    -0.866979   -0.800770   -0.156745    0.352786   -1.481404\n",
       "股票__3    -1.597172   -1.615793   -1.570001    0.398532    0.765573\n",
       "股票__4    -1.125884    0.161608   -0.561149   -1.953470   -1.089155\n",
       "股票__5    -0.516095    0.192761   -0.650655   -1.156976   -2.314995\n",
       "股票__6    -1.043859   -1.289673    0.305379    1.714618   -0.769184\n",
       "股票__7     0.704377    1.194555   -0.400249   -2.159789   -0.837449\n",
       "股票__8    -0.658431    2.121149    0.145063    1.388462    0.491103\n",
       "股票__9     1.293423    0.597727    0.584930    0.441140   -0.384639\n",
       "股票__10   -0.266614    1.015915   -0.759539   -0.516627    0.573710"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.08982429798715022"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_c[\"2019-04-03\"][\"股票__1\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    0\n",
       "1    1\n",
       "2    2\n",
       "3    3\n",
       "4    4\n",
       "5    5\n",
       "6    6\n",
       "7    7\n",
       "8    8\n",
       "9    9\n",
       "dtype: int32"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series(np.arange(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1     6.7\n",
       "2     5.6\n",
       "3     3.0\n",
       "4    10.0\n",
       "5     2.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series([6.7,5.6,3,10,2], index=[1,2,3,4,5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "series_demo = pd.Series({\"red\":10, \"green\":20})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['green', 'red'], dtype='object')"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series_demo.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([20, 10], dtype=int64)"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series_demo.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
